import web
import ho.pisa as pisa
import logging

urls = (
    '/pdftest', 'PdfTest',
    )

app = web.application(urls, globals())

class PdfTest:
    def GET(self):
        return '''
<html>
  <body>
    <form method="POST" action="pdftest" >
       <input type="text" name="text" />
       <input type="submit" value="Submit" />
    </form>

 </body>
</html>
'''
    def POST(self):
        html = web.input().text
        pdf = pisa.CreatePDF(html.encode('UTF-8'))
        web.header('Content-Type', 'application/pdf')
        return pdf.dest.getvalue()

        
if __name__ == '__main__':
    app.cgirun()
